local hx__jianggou = fk.CreateSkill {
  name = "hx__jianggou",
  tags = {Skill.Compulsory,}
}

hx__jianggou:addEffect(fk.Damaged, {
  anim_type = "control",
  trigger_times = function(self, event, target, player, data)
    return data.damage
  end,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__jianggou.name) and data.from
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice_card = room:askToCards(data.from, {
      min_num = 1,
      max_num = 1,
      skill_name = hx__jianggou.name,
      prompt = "#hx__jianggou-choose_card:" .. player.id,
    })
    if #choice_card > 0 then
      room:obtainCard(player, choice_card, true, fk.ReasonGive, data.from.id, hx__jianggou.name)
      local cards = data.from:getCardIds("he")
      local card = cards[math.random(1, #cards)]
      room:throwCard({card}, hx__jianggou.name, data.from, data.from)
    else
      room:loseHp(data.from, 2, hx__jianggou.name)
      room:damage({
        from = data.from,
        to = player,
        damage = 1,
        skillName = hx__jianggou.name,
      })
    end
  end,
})

return hx__jianggou